package com.ljw.community.service.impl;

import com.ljw.community.entity.Admin;
import com.ljw.community.mapper.AdminMapper;
import com.ljw.community.service.AdminService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AdminServiceImpl implements AdminService {

    @Resource
    private AdminMapper adminMapper;

    @Override
    public int count(String query, String type) {
        if (query == null) {
            query = "";
        }
        return adminMapper.count(query, type);
    }

    @Override
    public int modifyPwd(String oldPwd,String newPwd, String loginName) {
        Admin dbAdmin = adminMapper.getByLoginName(loginName);
        String dbPwd = dbAdmin.getPassword();
        if (!dbPwd.equals(oldPwd)){
            return -1;
        }
        return adminMapper.modifyPwdByLoginName(newPwd, loginName);
    }
}
